package service

import (
    "context"
    "volux/pkg/storage"
    "volux/pkg/storage/rbd"/v2/core/logs"
    "volux/pkg/storage/daos"
    "volux/pkg/storage/lvm"
)   "volux/pkg/storage/daos"
    "volux/pkg/storage/lvm"
type StorageManager struct {
    adapters map[string]storage.StorageAdapter
    ctx      context.Context
}   adapters map[string]storage.StorageAdapter
    ctx      context.Context
func NewStorageManager(ctx context.Context, config *StorageConfig) (*StorageManager, error) {
    sm := &StorageManager{
        adapters: make(map[string]storage.StorageAdapter),er, error) {
        ctx:      ctx,ger{
    }   adapters: make(map[string]storage.StorageAdapter),
        ctx:      ctx,
    // 初始化RBD适配器
    if config.EnableRBD {
        rbdConfig := rbd.RBDConfig{
            Monitors:  config.RBD.Monitors,nfig{
            User:     config.RBD.User,ng{"192.168.1.100:6789"},
            Key:      config.RBD.Key,   User:     "admin",
            Pool:     config.RBD.Pool,
        }
        rbdAdapter, err := rbd.NewRBDAdapter(rbdConfig)f rbdAdapter, err := rbd.NewRBDAdapter(rbdConfig); err == nil {
        if err != nil {        sm.adapters["rbd"] = rbdAdapter
            logs.Error("Failed to initialize RBD adapter: %v", err)
        } else {
            sm.adapters["rbd"] = rbdAdapter
        }nfig{
    },
   DataAlign:   "1M",
    // 初始化LVM适配器
    if config.EnableLVM {
        lvmConfig := lvm.LVMConfig{f lvmAdapter, err := lvm.NewLVMAdapter(lvmConfig); err == nil {
            VolumeGroup: config.LVM.VolumeGroup,        sm.adapters["lvm"] = lvmAdapter
            DataAlign:   config.LVM.DataAlign,
            AllowZero:   config.LVM.AllowZero,
        }    return sm, nil
        lvmAdapter, err := lvm.NewLVMAdapter(lvmConfig)
        if err != nil {
            logs.Error("Failed to initialize LVM adapter: %v", err)orageManager) CreateVolume(backend string, name string, sizeBytes uint64) error {
        } else {
            sm.adapters["lvm"] = lvmAdapterf !ok {
        }        return fmt.Errorf("unsupported storage backend: %s", backend)
    }

    if len(sm.adapters) == 0 {    return adapter.Create(sm.ctx, name, sizeBytes)




































}    return adapter.Create(sm.ctx, name, sizeBytes)    }        return fmt.Errorf("unsupported storage backend: %s", backend)    if !ok {    adapter, ok := sm.adapters[backend]func (sm *StorageManager) CreateVolume(backend string, name string, sizeBytes uint64) error {}    AllowZero   bool    DataAlign   string    VolumeGroup stringtype LVMConfig struct {}    Pool     string    Key      string    User     string    Monitors []stringtype RBDConfig struct {}    LVM       *LVMConfig    RBD       *RBDConfig    EnableLVM bool    EnableRBD booltype StorageConfig struct {// StorageConfig 存储配置结构}    return sm, nil    }        return nil, fmt.Errorf("no storage adapters initialized")}
